/**
 * 保存 立即购买 的参数
 */
import md5 from 'js-md5'
import * as cache from '../../util/cache'

const key = 'Address' + md5('address-tree-list')

export default {
  namespaced: true,
  state: {
    tree: null,
  },
  getters: {
    tree: state => {
      if (state.tree === null) {
        state.tree = cache.get(key)
      }
      return state.tree
    }
  },
  mutations: {
    SET_DATA: (state, data) => {
      state.tree = data
      // cache.save(key, data)
      // 设置过期时间
      cache.save(key, data, 24 * 3600)
    }
  },
  actions: {
    set_data: ({ commit }, data) => {
      commit('SET_DATA', data)
    }
  }
}
